﻿/*
 * Created by SharpDevelop.
 * User: pfraysier
 * Date: 7/3/2012
 * Time: 11:48 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace DTMTester
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		string fileName = String.Empty;
		
		void NewToolStripMenuItemClick(object sender, EventArgs e)
		{
			this.Text = "[Unnamed] - DTMTester";
			textBox1.Clear();
		}
		
		void OpenToolStripMenuItemClick(object sender, EventArgs e)
		{
			OpenFileDialog fDialog = new OpenFileDialog();
			fDialog.Title = "Select a text file";
			fDialog.Filter = "txt files|*.txt";
			fDialog.InitialDirectory = @"C:\";
			if(fDialog.ShowDialog() == DialogResult.OK)
			{
				fileName = fDialog.FileName;
				StreamReader sr = new StreamReader(fileName);
				string textFileContents = sr.ReadToEnd().ToString();
				textBox1.Text = (textFileContents);
				sr.Close();
				this.Text = fileName + " - DTMTester";
			}
		}
		
		void SaveToolStripMenuItemClick(object sender, EventArgs e)
		{
			// Trying to save a file before creating it.
			if(!this.Text.Equals("[Unnamed] - DTMTester"))
			{
				StreamWriter sw = new StreamWriter(fileName, false);
				sw.Write(textBox1.Text);
				sw.Close();
			}
			// Overwrites old file.
			else
			{
				SaveFileDialog fDialog = new SaveFileDialog();
				fDialog.Title = "Saving file...";
				fDialog.Filter = "txt files|*.txt";
				fDialog.InitialDirectory = @"C:\";
				if(fDialog.ShowDialog() == DialogResult.OK)
				{
					fileName = fDialog.FileName;
					StreamWriter sw = new StreamWriter(fileName, false);
					sw.Write(textBox1.Text);
					sw.Close();
					this.Text = fDialog.FileName + " - DTMTester";
				}
			}
		}
		
		void SaveAsToolStripMenuItemClick(object sender, EventArgs e)
		{
			SaveFileDialog fDialog = new SaveFileDialog();
			fDialog.Title = "Saving file...";
			fDialog.Filter = "txt files|*.txt";
			fDialog.InitialDirectory = @"C:\";
			if(fDialog.ShowDialog() == DialogResult.OK)
			{
				fileName = fDialog.FileName;
				StreamWriter sw = new StreamWriter(fileName, false);
				sw.Write(textBox1.Text);
				sw.Close();
				this.Text = fDialog.FileName + " - DTMTester";
			}
		}
		
		void ImportExportToolStripMenuItemClick(object sender, EventArgs e)
		{
			
		}
		
		void InfoToolStripMenuItemClick(object sender, EventArgs e)
		{
			
		}
		
		void RecentFilesToolStripMenuItemClick(object sender, EventArgs e)
		{
			
		}
		
		void ExitToolStripMenuItemClick(object sender, EventArgs e)
		{
			Application.Exit();
		}
	}
}
